package com.liu.security.exception;

import com.liu.security.pojo.http.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 统一 运行时异常 包装异常返回
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public ApiResponse handleException(CustomException ex) {
        log.info("GlobalExceptionHandler Exception = {}", ex.getMessage());
        return new ApiResponse<>(ex.getMessage(), null,ex.getCode());
    }
}
